package com.shiro.demo.filter;

import org.apache.shiro.web.filter.authc.AuthenticationFilter;
import org.apache.shiro.web.filter.authz.AuthorizationFilter;

import javax.security.auth.Subject;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class RolesorFilter  extends AuthorizationFilter {
    @Override
    protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) throws Exception {
        org.apache.shiro.subject.Subject subject=getSubject(servletRequest,servletResponse);
           String[] roles=(String[])o;
           if (roles==null||roles.length==0){
               return  true;
           }
           for(String role:roles){
               if (subject.hasRole(role)){
                   return  true;
               }
           }
        return false;


    }
}
